import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:xiongan_app_yy/pages/norder_audit_result/tab_norderauditresult_one.dart';
import 'package:xiongan_app_yy/pages/norder_audit_result/tab_norderauditresult_two.dart';
import 'package:xiongan_app_yy/provider/norderauditresult_info.dart';
import 'package:xiongan_app_yy/widgets/comm/left_icon_widget.dart';
import 'package:xiongan_app_yy/common/user_singleton.dart';
import 'package:xiongan_app_yy/entrys/rp/inv_list_entity.dart';
import 'package:xiongan_app_yy/net/internet_api.dart';
import 'package:xiongan_app_yy/widgets/comm/label_select.dart';

//自动上架
class NorderAuditResult extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _NorderAuditResult();
  }
}

//ListWidget
class _NorderAuditResult extends State<NorderAuditResult>
    with SingleTickerProviderStateMixin {
  final List<Map<String, dynamic>> _data = List();
  InvListEntity invListEntity;
  int size = 0;
  List<String> _labelText = ['未审核', '审核通过', "审核未通过", "已废弃"];
  int selected = -1;
  TabController _tabController;

  final List<Tab> titleList = <Tab>[
    new Tab(
      text: '入库任务',
    ),
    new Tab(
      text: '出库任务',
    ),
  ];

  // List<norder_audit_result> unauditedList = new List();
  // List<norder_audit_result> auditPassList = new List();
  // List<norder_audit_result> auditFailedList = new List();
  // List<norder_audit_result> exhibitionList = new List();

  // 迭代器生成list
  Iterable<Widget> get _inputSelects sync* {
    for (int i = 0; i < _labelText.length; i++) {
      yield InputSelect(
        index: i,
        choice: _labelText[i],
        parent: this,
      );
    }
  }

  onSelectedChanged(int index) {
    setState(() {
      selected = index;
    });
  }

  @override
  void initState() {
    super.initState();
    _tabController = new TabController(vsync: this, length: titleList.length);
    _tabController.addListener(() {
      print(_tabController.index);
      Provider.of<NorderauditresultInfo>(context)
          .setTabIndex(_tabController.index);
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      endDrawer: Drawer(
        child: Container(
          padding: EdgeInsets.only(left: 10, right: 10),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                  margin: EdgeInsets.only(top: 80, bottom: 10),
                  child: Text("审核状态",
                      style:
                          TextStyle(fontSize: 14, color: Color(0xFF646464)))),
              Expanded(
                child: Wrap(
                  children: _inputSelects.toList(),
                ),
              ),
              Container(
                  margin: EdgeInsets.only(bottom: 20),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: <Widget>[
                      FlatButton(
                          onPressed: () {
                            Provider.of<NorderauditresultInfo>(context)
                                .setSelected(-1);
                            Navigator.pop(context);
                          },
                          child: Text(
                            "重置",
                            style: TextStyle(color: Color(0xFF00A5F1)),
                          ),
                          color: Color(0xFFE9E9E9),
                          shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.only(
                                  bottomLeft: Radius.circular(20),
                                  topLeft: Radius.circular(20)))),
                      FlatButton(
                          onPressed: () {
                            print(selected);
                            Provider.of<NorderauditresultInfo>(context)
                                .setSelected(selected);
                            Navigator.pop(context);
                          },
                          child: Text(
                            "确定",
                            style: TextStyle(color: Colors.white),
                          ),
                          color: Color(0xFF00A5F1),
                          shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.only(
                                  bottomRight: Radius.circular(20),
                                  topRight: Radius.circular(20))))
                    ],
                  ))
            ],
          ),
        ),
      ),
      appBar: AppBar(
        leading: LeftIconWidget(icon: Icons.chevron_left, isize: 36),
        backgroundColor: Color(0XFF00A5F1),
        title: Text(
          "非预约审核结果",
          style: TextStyle(fontSize: 18),
        ),
        actions: <Widget>[
          new IconButton(
            // action button
            padding: EdgeInsets.only(),
            iconSize: 22,
            icon: new Icon(IconData(0xe617, fontFamily: "wuIconFont")),
            onPressed: () {
              Navigator.pushNamed(context, '/norderAuditResultSearch',arguments: _tabController.index);
            },
          ),
          Builder(
            builder: (context) => new IconButton(
              // action button
              iconSize: 18,
              icon: new Icon(IconData(0xe621, fontFamily: "wuIconFont")),
              onPressed: () {
                Scaffold.of(context).openEndDrawer();
              },
            ),
          ),
        ],
        elevation: 0,
        centerTitle: true,
        bottom: PreferredSize(
          preferredSize: Size.fromHeight(48),
          child: Material(
              color: Colors.white,
              child: Stack(
                alignment: Alignment.center,
                children: <Widget>[
                  new TabBar(
                    controller: _tabController,
                    tabs: titleList,
                    indicatorColor: Color(0XFF00A5F1),
                    labelColor: Color(0XFF00A5F1),
                    unselectedLabelColor: Color(0XFF646464),
                    indicatorPadding: EdgeInsets.only(bottom: 0),
                    indicatorSize: TabBarIndicatorSize.label,
                  ),
                ],
              )),
        ),
      ),
      body: new TabBarView(
        controller: _tabController,
        children: [
          TabNorderauditresultOne(),
          TabNorderauditresultTwo(),
        ],
      ),
      /*Scrollbar(
          child: ListView.separated(
              itemBuilder: (BuildContext context, int index) {
                return TextCartItem(
                  data: _data,
                  index: index,
                );
              },
              separatorBuilder: (BuildContext context, int index) {
                return Divider(color: Colors.black26);
              },
              itemCount: _data.length)),*/
    );
  }
}
